//
//  PersonHeaderView.m
//  KeleAppProject
//
//  Created by Cen Zhou on 2018/1/18.
//  Copyright © 2018年 Cen Zhou. All rights reserved.
//

#import "PersonHeaderView.h"

@interface PersonHeaderView()

@property (nonatomic, strong) UIButton *attentButton;

@end


@implementation PersonHeaderView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = KLColor_A1;
        [self loadSubviewsOnPersonalView];
    }
    return self;
}


- (void)loadSubviewsOnPersonalView{
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [backButton setBackgroundImage:[UIImage imageNamed:@"icon_fanhui_baise"] forState:UIControlStateNormal];
    [[backButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
        if (self.delegateSignal) {
            [self.delegateSignal sendNext:nil];
        }
    }];
    [self addSubview:backButton];
    [backButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(15*WIDTH);
        make.top.equalTo(self).offset(32*HEIGHT);
        make.width.mas_equalTo(20*WIDTH);
        make.height.mas_equalTo(20*HEIGHT);
    }];
    
    UIView *profileBgView = [[UIView alloc]init];
    profileBgView.backgroundColor = KLColor(255, 255, 255, 0.28);
    profileBgView.layer.cornerRadius = 33*WIDTH;
    [self addSubview:profileBgView];
    [profileBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(74*HEIGHT);
        make.left.equalTo(self).offset(15*WIDTH);
        make.width.height.mas_equalTo(66*WIDTH);
    }];
    
    UIImageView  *profileImageView = [[UIImageView alloc]init];
    profileImageView.image = [UIImage imageNamed:@"info_touxiang"];
    profileImageView.contentMode = UIViewContentModeScaleAspectFit;
    profileImageView.layer.cornerRadius = 28*WIDTH;
    [profileBgView addSubview:profileImageView];
    profileImageView.userInteractionEnabled = YES;
    [profileImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(profileBgView);
        make.width.height.mas_equalTo(56*WIDTH);
    }];
    
    UILabel *nameLb = [[UILabel alloc]init];
    nameLb.text = @"哈哈哈";
    nameLb.textColor = [UIColor whiteColor];
    nameLb.font = [UIFont fontWithName:@"PingFangSC-Regular" size:18*WIDTH];
    [self addSubview:nameLb];
    [nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(profileBgView);
        make.left.equalTo(profileBgView.mas_right).offset(15*WIDTH);
    }];
    // 关注
    UILabel *attentTint = [[UILabel alloc]init];
    attentTint.text = @"关注:";
    attentTint.textColor = [UIColor whiteColor];
    attentTint.font = [UIFont fontWithName:@"PingFangSC-Regular" size:13*WIDTH];
    [self addSubview:attentTint];
    [attentTint mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(nameLb);
        make.top.equalTo(nameLb.mas_bottom).offset(12*HEIGHT);
    }];
    UILabel *attentNum = [[UILabel alloc]init];
    attentNum.text = @"238";
    attentNum.textColor = [UIColor whiteColor];
    attentNum.font = [UIFont fontWithName:@"PingFangSC-Regular" size:16*WIDTH];
    [self addSubview:attentNum];
    [attentNum mas_makeConstraints:^(MASConstraintMaker *make) {
         make.top.equalTo(nameLb.mas_bottom).offset(9*HEIGHT);
        make.left.equalTo(attentTint.mas_right).offset(3*WIDTH);
    }];
    
    // fensi
    UILabel *fanceTint = [[UILabel alloc]init];
    fanceTint.text = @"粉丝:";
    fanceTint.textColor = [UIColor whiteColor];
    fanceTint.font = [UIFont fontWithName:@"PingFangSC-Regular" size:13*WIDTH];
    [self addSubview:fanceTint];
    [fanceTint mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(attentNum.mas_right).offset(15*WIDTH);
        make.top.equalTo(attentTint);
    }];
    
    UILabel *fanceNum = [[UILabel alloc]init];
    fanceNum.text = @"564";
    fanceNum.textColor = [UIColor whiteColor];
    fanceNum.font = [UIFont fontWithName:@"PingFangSC-Regular" size:16*WIDTH];
    [self addSubview:fanceNum];
    [fanceNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(nameLb.mas_bottom).offset(9*HEIGHT);
        make.left.equalTo(fanceTint.mas_right).offset(3*WIDTH);
    }];
    
    // 关注按钮
    UIButton *attentButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [attentButton setImage:[UIImage imageNamed:@"info_icon_guanzhu_add"] forState:UIControlStateNormal];
    [attentButton setTitle:@"关注" forState:UIControlStateNormal];
    attentButton.backgroundColor = [UIColor whiteColor];
    [attentButton setTitleColor:KLColor_A1 forState:UIControlStateNormal];
    attentButton.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:13*WIDTH];
    [attentButton setImageEdgeInsets:UIEdgeInsetsMake(0, 0,0, 0)];
    [self addSubview:attentButton];
    self.attentButton = attentButton;
    [[attentButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(UIButton *x) {
        if ([x.titleLabel.text isEqualToString:@"关注"]) {
            x.backgroundColor = KLColor(0, 0, 0, 0.18);
            [x setTitle:@"取消关注" forState:UIControlStateNormal];
            [x setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];

        }else{
            [x setTitle:@"关注" forState:UIControlStateNormal];
            x.backgroundColor = [UIColor whiteColor];
            [x setImage:[UIImage imageNamed:@"info_icon_guanzhu_add"] forState:UIControlStateNormal];

        }
    }];
    [attentButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(nameLb);
        make.right.equalTo(self).offset(-15*WIDTH);
        make.height.mas_equalTo(24*HEIGHT);
        make.width.mas_equalTo(66*WIDTH);
    }];
    
    // 简介
    UILabel *introduceTint = [[UILabel alloc]init];
    introduceTint.text = @"简介:";
    introduceTint.textColor = KLColor(255, 255, 255, 0.8);
    introduceTint.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12*WIDTH];
    [self addSubview:introduceTint];
    [introduceTint mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(profileBgView);
        make.top.equalTo(profileBgView.mas_bottom).offset(18*HEIGHT);
    }];
    
    UILabel *introduceLb = [[UILabel alloc]init];
    introduceLb.text = @"肯定建安费绝地反击按房间解答即可了解的开发贷款拉克； 打开了发来看看你";
    introduceLb.numberOfLines = 2;
    introduceLb.textColor = KLColor(255, 255, 255, 0.8);
    introduceLb.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12*WIDTH];
    [self addSubview:introduceLb];
    [introduceLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(introduceTint.mas_right).offset(6*WIDTH);
        make.top.equalTo(introduceTint);
        make.width.mas_equalTo(311*WIDTH);
    }];
    
}



- (void)layoutSublayersOfLayer:(CALayer *)layer{
    [super layoutSublayersOfLayer:layer];
    [self.attentButton layoutIfNeeded];
    [self.attentButton setRadiusWithValue:2];
}


@end
